
/*
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  These are the four essential freedoms with GNU GPL software:
 *  1: freedom to run the program, for any purpose
 *  2: freedom to study how the program works, and change it to make it do what you wish
 *  3: freedom to redistribute copies to help your Free Software friends
 *  4: freedom to distribute copies of your modified versions to your Free Software friends
 *   ,           ,
 *  /             \
 * ((__-^^-,-^^-__))
 * `-_---'  `---_-'
 *  `--|o`   'o|--'
 *      \  `  /
 *       ): :(
 *       :o_o:
 *        "-"
 *
 * SPDX-License-Identifier: GPL-3.0+
 * License-Filename: LICENSE
 */

#include "config.h"

#include <stdio.h>
#include <stdlib.h>

#include "main.h"
#include "ast.h"
#include "list.h"

static struct node *make_node(struct ast *ast)
{
	struct node *tmp = calloc(1, sizeof(struct node));
	tmp->data = ast;
	tmp->next = NULL;
	return tmp;
}

struct list *nil_list(void)
{
	struct list *tmp = (struct list *)calloc(1, sizeof(struct list));
	tmp->head = NULL;
	tmp->tail = NULL;
	return tmp;
}

struct list *single_list(struct ast *ast)
{
	struct node *nn = NULL;
	struct list *tmp = nil_list();
	nn = make_node(ast);
	tmp->head = nn;
	tmp->tail = nn;
	return tmp;
}

struct list *append_list(struct list *l1, struct list *l2)
{
	if (l1 == NULL) {
		return l2;
	}
	if (l2 == NULL) {
		return l1;
	}

	if (l1->head == NULL) {
		l1->head = l2->head;
		l1->tail = l2->tail;
	} else {
		l1->tail->next = l2->head;
		l1->tail = l2->tail;
	}

	return l1;
}

/* end. */
